﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.ZhiJian
{
    public partial class ZhiLiangShu_MingXi_ToZhiJian : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Label1.Text = Request.QueryString["luhao"];
                this.Label2.Text = Request.QueryString["luhao"];
            }
            this.GridView1.SelectedIndex = 0;
        }

        //protected void Save_Click(object sender, EventArgs e)
        //{
        //    //SqlConnection Conn = new SqlConnection();
        //    //Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
        //    //Conn.Open();
        //    //SqlTransaction Tran = Conn.BeginTransaction();
        //    //SqlCommand Cmd = new SqlCommand();
        //    //Cmd.Connection = Conn;
        //    //Cmd.Transaction = Tran;
        //    //try
        //    //{
        //    //    Cmd.CommandText = "ZhiLiangShu_MingXi_ToZhiJian_Update";
        //    //    Cmd.CommandType = CommandType.StoredProcedure;
        //    //    string luhao = Request.QueryString["luhao"];
        //    //    string id = Request.QueryString["id"];
        //    //    Cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, int.Parse(id)));
        //    //    Cmd.Parameters.Add(new SqlParameter("@炉号", SqlDbType.NVarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed,luhao));
        //    //    Cmd.Parameters.Add(new SqlParameter("@C", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.C.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Mn", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Mn.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Si", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed,this.Si.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@P", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.P.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@S", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.S.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Cr", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Cr.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Ni", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Ni.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Cu", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Cu.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Mo", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Mo.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Al", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Al.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@V", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.V.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Bi", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed,this.Bi.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Sn", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Sn.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Pb", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Pb.Text));              
        //    //    Cmd.Parameters.Add(new SqlParameter("@As", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.As.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@Sb", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Sb.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@抗拉强度", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed,this.klqd.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@屈伸极限", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.qsjx.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@伸长率", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed,this.scl.Text ));
        //    //    Cmd.Parameters.Add(new SqlParameter("@横向冲击", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed,this.hx.Text ));
        //    //    Cmd.Parameters.Add(new SqlParameter("@纵向冲击", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed,this.zx.Text ));
        //    //    Cmd.Parameters.Add(new SqlParameter("@通径检验", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.tj.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@静水压试验", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed,this.jsy.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@无损探伤", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed,this.ws.Text ));
        //    //    Cmd.Parameters.Add(new SqlParameter("@表面检验", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed,this.bm.Text));
        //    //    Cmd.Parameters.Add(new SqlParameter("@尺寸", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.cc.Text));
                                
        //    //    Cmd.ExecuteNonQuery();            
        //    //    this.Message.Text = "·保存成功";
               
        //    //    Tran.Commit();
        //    //}
        //    //catch (Exception err)
        //    //{
               
        //    //    Tran.Rollback();
        //    //    this.Message.Text = err.Message;
        //    //}
        //    //Cmd.Dispose();
        //    //Tran.Dispose();
        //    //Conn.Close();
        //    //Conn.Dispose();
        //    //this.GridView1.DataSourceID = this.SqlDataSource1.ID;
        //}
      
        protected void GridView1_DataBound(object sender, EventArgs e)
        {
            this.TextBox_Pager.Text = (this.GridView1.PageIndex + 1).ToString();
            this.Label_Pages.Text = " 共" + this.GridView1.PageCount.ToString() + "页 ";

            this.Button_Pager_First.CssClass = "pageturn-first-b";
            this.Button_Pager_First.Enabled = true;
            this.Button_Pager_Prev.CssClass = "pageturn-prev-b";
            this.Button_Pager_Prev.Enabled = true;
            this.Button_Pager_Next.CssClass = "pageturn-next-b";
            this.Button_Pager_Next.Enabled = true;
            this.Button_Pager_Last.CssClass = "pageturn-last-b";
            this.Button_Pager_Last.Enabled = true;
            if (this.GridView1.PageIndex == 0)
            {
                this.Button_Pager_Prev.CssClass = "pageturn-prev-g";
                this.Button_Pager_Prev.Enabled = false;
            }
            if (this.GridView1.PageIndex < 2)
            {
                this.Button_Pager_First.CssClass = "pageturn-first-g";
                this.Button_Pager_First.Enabled = false;
            }
            if (this.GridView1.PageIndex == this.GridView1.PageCount - 1 || this.GridView1.PageCount == 0)
            {
                this.Button_Pager_Next.CssClass = "pageturn-next-g";
                this.Button_Pager_Next.Enabled = false;

            }
            if (this.GridView1.PageIndex > this.GridView1.PageCount - 3)
            {
                this.Button_Pager_Last.CssClass = "pageturn-last-g";
                this.Button_Pager_Last.Enabled = false;
            }

        }
        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            this.GridView1_DataBound(null, null);

        }
        protected void Pager_Click(object sender, EventArgs e)
        {
            if (sender.GetType().ToString() == "System.Web.UI.WebControls.Button")
            {
                switch (((Button)sender).CommandName)
                {
                    case "--":
                        this.GridView1.PageIndex = 0;
                        break;
                    case "-":
                        if (this.GridView1.PageIndex > 0) this.GridView1.PageIndex--;
                        break;
                    case "+":
                        if (this.GridView1.PageIndex < this.GridView1.PageCount - 1) this.GridView1.PageIndex++;
                        break;
                    case "++":
                        this.GridView1.PageIndex = this.GridView1.PageCount - 1;
                        break;
                }
            }
            else
            {

                int p;
                if (int.TryParse(TextBox_Pager.Text, out p))
                {
                    if (p >= 1 && p <= this.GridView1.PageCount)
                    {
                        this.GridView1.PageIndex = p - 1;
                    }
                }
                TextBox_Pager.Text = (this.GridView1.PageIndex + 1).ToString();
            }

        }

        protected void Add_Click(object sender, EventArgs e)
        {
            this.Panel2.Visible = true;
        }      

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            ((TextBox)GridView1.Rows[GridView1.SelectedIndex].Cells[1].FindControl("TextBox1")).ReadOnly = false;
        }           
    }
}
